{% extends "common/base.html" %}

{% block title %}复制 - {{ block.Super }}{% endblock %}

{% block wrapper %}
<style>
.main-box {
    margin-bottom: 0;
    margin: 15px;
}
.main-box .main-box-body {
    padding: 20px;
}
@media screen and (max-width: 767px) {
    .table-responsive {
        margin-bottom: 0;
    }
}
</style>

<script src='{{ assets("js/jquery.js") }}' type="text/javascript"></script>
<script src='{{ assets("js/layer/layer.js") }}' type="text/javascript"></script>

<div class="main-box clearfix">
    <header class="main-box-header clearfix">
        <div class="pull-left">
            <h2>文件列表</h2>
            
            {% if path == "" %}
                <div class="fs-path" id="fs-path" data-path="/">/</div>
            {% else %}
                <div class="fs-path" id="fs-path" data-path="{{ path }}">{{ path }}</div>
            {% endif %}
        </div>
    </header>

    <div class="main-box-body clearfix">
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>
                            <span>名称</span>
                        </th>
                        <th>
                            <span>修改时间</span>
                        </th>
                        <th>
                            <span>权限</span>
                        </th>
                    </tr>
                </thead>

                <tbody>
                    {% if parentPath != "" %}
                        <tr>
                            <td class="sys-name" colspan="7" data-name="{{ parentPath }}">
                                <a href="/file/copy?old={{ old }}&path={{ parentPath }}" title="返回上级">..</a>
                            </td>
                        </tr>
                    {% endif %}

                    {% for item in list %}
                        <tr>
                            <td class="sys-name">
                                <a href="/file/copy?old={{ old }}&path={{ path }}/{{ item.namesmall }}" title="{{ item.namesmall }}">{{ item.namesmall }}</a>
                            </td>
                            <td>
                                {{ item.time }}
                            </td>
                            <td>
                                {{ item.perm }}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        
        <form role="form">
            <input type="hidden" id="old-name" value="{{ old }}" />
            <div class="form-group">
                <button type="button" class="btn btn-success pull-right js-save-btn">确认复制</button>
            </div>
        </form>

    </div>
</div>
{% endblock %}

{% block script %}
<script type="text/javascript">
;(function($) {
    "use strict";
    
    // 保存
    $(".js-save-btn").click(function(e) {
        e.stopPropagation;
        e.preventDefault;

        var oldName = $("#old-name").val();
        var newName = "{{ path }}";

        var url = '/file/copy';
        $.post(url, {
            old_name: oldName,
            new_name: newName,
        }, function(data) {
            if (data.code == 0) {
                layer.msg(data.message);
                
                setTimeout(function() {
                    window.location.reload();
                }, 1500);
            } else {
                layer.msg(data.message);
            }
        }).fail(function (xhr, status, info) {
            layer.msg("请求失败");
        });
    });
})(jQuery);
</script>
{% endblock %}